const Service = require("egg").Service;

class MenuService extends Service {
  async queryMenu(siteId) {
    const TMenu = this.app.model.TMenu
    async function getRecursiveMenus(siteId,parentId ) {
      const results = [];
      const menus = await TMenu.findAll({
        where: { parentId,siteId },
      });
      for (const menu of menus) {
        console.log("menumenu", menu);
        const children = await getRecursiveMenus(siteId,menu.id);
        results.push({ ...menu.toJSON(), children });
      }
      return results;
    }
    return await getRecursiveMenus(siteId,0);
  }
}
module.exports = MenuService;
